package org.mclll.xwangplugin.dengmi.listener;

import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.boss.KeyedBossBar;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.mclll.xwangplugin.dengmi.GameQuestion;

public class DengMiListener implements Listener {

    // 玩家加入时判断有没有显示题目
    @EventHandler
    public void playerJoin(PlayerJoinEvent event) {
        // 不在游戏中就直接return了
        if (!GameQuestion.isGaming()) {
            return;
        }
        Player player = event.getPlayer();
        for (int i = 0; i < 3; i++) {
            KeyedBossBar bar = Bukkit.getServer().getBossBar(new NamespacedKey("mclll", "xw" + i));
            if (bar != null) {
                bar.addPlayer(player);
            }
        }
    }

    @EventHandler
    public void confirmSetHome(final AsyncPlayerChatEvent event) {
        // 不在游戏中就直接return了
        if (!GameQuestion.isGaming()) {
            return;
        }
        Player player = event.getPlayer();
        GameQuestion.checkAnswer(player, event);
    }
}
